package wireless.feature.action;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import wireless.feature.pojo.Feature;

public class FeatureLoad {

	private String file1;
	private String file2;
	private String file3;
	private String file4;
	private String file5;
	private String file6;
	
	private List<Feature> list1 = new ArrayList<Feature>();
	private List<Feature> list2 = new ArrayList<Feature>();
	private List<Feature> list3 = new ArrayList<Feature>();
	private List<Feature> list4 = new ArrayList<Feature>();
	private List<Feature> list5 = new ArrayList<Feature>();
	private List<Feature> list6 = new ArrayList<Feature>();
	
	public String getFile1() {
		return file1;
	}
	public void setFile1(String file1) {
		this.file1 = file1;
	}
	public String getFile2() {
		return file2;
	}
	public void setFile2(String file2) {
		this.file2 = file2;
	}
	public String getFile3() {
		return file3;
	}
	public void setFile3(String file3) {
		this.file3 = file3;
	}
	public String getFile4() {
		return file4;
	}
	public void setFile4(String file4) {
		this.file4 = file4;
	}
	public String getFile5() {
		return file5;
	}
	public void setFile5(String file5) {
		this.file5 = file5;
	}
	public String getFile6() {
		return file6;
	}
	public void setFile6(String file6) {
		this.file6 = file6;
	}
	
	
	public List<Feature> getList1() {
		return list1;
	}
	public void setList1(List<Feature> list1) {
		this.list1 = list1;
	}
	
	public List<Feature> getList2() {
		return list2;
	}
	public void setList2(List<Feature> list2) {
		this.list2 = list2;
	}
	public List<Feature> getList3() {
		return list3;
	}
	public void setList3(List<Feature> list3) {
		this.list3 = list3;
	}
	public List<Feature> getList4() {
		return list4;
	}
	public void setList4(List<Feature> list4) {
		this.list4 = list4;
	}
	public List<Feature> getList5() {
		return list5;
	}
	public void setList5(List<Feature> list5) {
		this.list5 = list5;
	}
	public List<Feature> getList6() {
		return list6;
	}
	public void setList6(List<Feature> list6) {
		this.list6 = list6;
	}
	public String execute() throws Exception {
		
		list1 = readFileByLines(file1);
		list2 = readFileByLines(file2);
		list3 = readFileByLines(file3);
		list4 = readFileByLines(file4);
		list5 = readFileByLines(file5);
		list6 = readFileByLines(file6);
		
		System.out.println("length:"+list1.get(0).getLength());
		System.out.println("value:"+list1.get(0).getValue());
		return "success";
	}
	
	/**
     * 以行为单位读取文件，常用于读面向行的格式化文件
     */
    public static List<Feature> readFileByLines(String fileName) {
        File file = new File(fileName);
        List<Feature> list = new ArrayList<Feature>();
        BufferedReader reader = null;
        try {
            System.out.println("以行为单位读取文件内容，一次读一整行：");
            reader = new BufferedReader(new FileReader(file));
            String tempString = null;
            int line = 0;
            // 一次读入一行，直到读入null为文件结束
            while ((tempString = reader.readLine()) != null) {
                // 显示行号
                System.out.println("line " + line + ": " + tempString);
                Feature feature = new Feature();
                feature.setId(line+1);
                feature.setLength(Integer.parseInt(tempString.split(" ")[0]));
                feature.setValue(tempString.split(" ")[1]);
                list.add(feature);
                line++;
            }
            reader.close();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (reader != null) {
                try {
                    reader.close();
                } catch (IOException e1) {
                }
            }
        }
        return list;
    }
	
}
